﻿Imports System.ComponentModel

Public Interface ITraitement
    ReadOnly Property Name As String
    ReadOnly Property Parents As IEnumerable(Of ITraitement)
    ReadOnly Property Children As IEnumerable(Of ITraitement)
    ReadOnly Property State As EtatTraitement
    ReadOnly Property IsLocked As Boolean

    Sub AddDependency(ByVal dependency As ITraitement)
    Sub RemoveDependency(ByVal dependency As ITraitement)

    Function GetResult(ByVal key As String) As Object

    Event StateChanged As EventHandler
End Interface

Public Interface ILocalTraitement
    Inherits ITraitement


End Interface

Public Interface IServerTraitement
    Inherits ITraitement


End Interface

Public Interface IMixedTraitement

End Interface

Public Enum EtatTraitement
    Reseted
    Executing
    Canceling
    Canceled
    ExecutionSuccess
    ExecutionFailed
End Enum

Public Class LocalTraitement
    Implements ILocalTraitement
    Implements INotifyPropertyChanged

    Sub New()

    End Sub
    Sub New(ByVal name As String)

    End Sub

    Private _Children As New List(Of ITraitement)
    Private _Parents As New List(Of ITraitement)
    Private Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    Private _Name As String

    Public Sub AddDependency(ByVal dependency As ITraitement) Implements ITraitement.AddDependency
        Dim lt = TryCast(dependency, LocalTraitement)
        If lt IsNot Nothing Then
            _Children.Add(lt)
            lt._Parents.Add(Me)
        End If
    End Sub
    Public Sub RemoveDependency(ByVal dependency As ITraitement) Implements ITraitement.RemoveDependency
        Dim lt = TryCast(dependency, LocalTraitement)
        If lt IsNot Nothing Then
            _Children.Remove(lt)
            lt._Parents.Remove(Me)
        End If
    End Sub

    Public ReadOnly Property Children As System.Collections.Generic.IEnumerable(Of ITraitement) Implements ITraitement.Children
        Get
            Return _Children
        End Get
    End Property
    Public ReadOnly Property Parents As System.Collections.Generic.IEnumerable(Of ITraitement) Implements ITraitement.Parents
        Get
            Return _Parents
        End Get
    End Property
    Public ReadOnly Property Etat As EtatTraitement Implements ITraitement.State
        Get

        End Get
    End Property

    Public Event EtatAChange As EventHandler Implements ITraitement.StateChanged

    Public Function GetResult(ByVal key As String) As Object Implements ITraitement.GetResult

    End Function
    Public ReadOnly Property IsLocked As Boolean Implements ITraitement.IsLocked
        Get
            Return False
        End Get
    End Property
    Public ReadOnly Property Name As String Implements ITraitement.Name
        Get
            Return Me._Name
        End Get
    End Property

    Public Overridable Sub Execute()
        RaiseEvent EtatAChange(Me, EventArgs.Empty)
    End Sub
End Class

Public Class Test
    Sub f()
        Dim t1 As New LocalTraitement("oo")
        t1.AddDependency(New LocalTraitement("okk"))
        Dim t2 As New LocalTraitement("oko")
        t2.AddDependency(t1)
        t2.AddDependency(t1.Children.First())
    End Sub
End Class

Public Class ServerTraitement
    Implements IServerTraitement
    Implements INotifyPropertyChanged


    Sub New(ByVal name As String)

    End Sub

    Private _Children As New List(Of ITraitement)
    Private _Parents As New List(Of ITraitement)
    Private Event PropertyChanged As PropertyChangedEventHandler Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
    Private _Name As String

    Public Sub AddDependency(ByVal dependency As ITraitement) Implements ITraitement.AddDependency
        Dim lt = TryCast(dependency, ServerTraitement)
        If lt IsNot Nothing Then
            _Children.Add(lt)
            lt._Parents.Add(Me)
        End If
    End Sub
    Public Sub RemoveDependency(ByVal dependency As ITraitement) Implements ITraitement.RemoveDependency
        Dim lt = TryCast(dependency, ServerTraitement)
        If lt IsNot Nothing Then
            _Children.Remove(lt)
            lt._Parents.Remove(Me)
        End If
    End Sub

    Public ReadOnly Property Children As System.Collections.Generic.IEnumerable(Of ITraitement) Implements ITraitement.Children
        Get
            Return _Children
        End Get
    End Property
    Public ReadOnly Property Parents As System.Collections.Generic.IEnumerable(Of ITraitement) Implements ITraitement.Parents
        Get
            Return _Parents
        End Get
    End Property
    Public ReadOnly Property Etat As EtatTraitement Implements ITraitement.State
        Get

        End Get
    End Property

    Public Event EtatAChange As EventHandler Implements ITraitement.StateChanged

    Public Function GetResult(ByVal key As String) As Object Implements ITraitement.GetResult

    End Function
    Public ReadOnly Property IsLocked As Boolean Implements ITraitement.IsLocked
        Get
            Return False
        End Get
    End Property
    Public ReadOnly Property Name As String Implements ITraitement.Name
        Get
            Return Me._Name
        End Get
    End Property

    Public Overridable Sub Execute()
        RaiseEvent EtatAChange(Me, EventArgs.Empty)
    End Sub
End Class

Public Class FastTable


End Class